﻿using System.Collections.Generic;
using DataScripter.Containers;
using DataScripter.Scripting.Processes.Output;

namespace DataScripter.Scripting.Processes
{
    public class WriteDataSetToXmlProcess : BaseProcess
    {
        private string Filename { get; set; }

        public WriteDataSetToXmlProcess(string name, IContainer container)
            : base(name, container)
        {
        }

        #region Overrides of BaseProcess

        public override IProcessOutput Run()
        {
            RunParents();
            if (State == ProcessState.Error)
                return null;

            DataSetProcessOutput processOutput = (DataSetProcessOutput) InputProcesses[0].Output;
            processOutput.DataSet.WriteXml(Filename);
            return new FileProcessOutput {Filename = Filename};
        }

        public override void Initialize(Dictionary<string, string> parameters)
        {
            Filename = parameters["FileName"];
        }

        #endregion
    }
}
